package com.app.fenak;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity {

//	private ImageView forgetPasswordButton;
	private Button loginButton;
//	private ImageView signUpButton;
	private EditText username;
	private EditText password;
	private TextView forgetPassword ;
	private TextView signUp ;

	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.login);

		loginButton = (Button) findViewById(R.id.login_button);
//		forgetPasswordButton = (ImageView) findViewById(R.id.forget_password_button);
//		signUpButton = (ImageView) findViewById(R.id.signup_button);
		username = (EditText) findViewById(R.id.username_field);
		password = (EditText) findViewById(R.id.password_field);
		forgetPassword = (TextView) findViewById(R.id.forget_password_text);
		signUp = (TextView) findViewById(R.id.sign_up_text);

	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();

		loginButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				String usernameString = username.getText().toString();
				String passwordString = password.getText().toString();

				Log.i("username", usernameString);
				Log.i("password", passwordString);

				if (!(usernameString.equalsIgnoreCase("") || passwordString
						.equalsIgnoreCase(""))) {

					// i will send them to the server api to test them
					
					// if the return from the server is true
//					intent = new Intent(LoginActivity.this,
//							FenakActivity.class);
//					LoginActivity.this.startActivity(intent);
					
					//else if the return is false
					AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); 
					builder.setTitle("Error")
					.setPositiveButton("Ok", null)
					.setMessage("Incorrect username or password");
					AlertDialog alertDialog = builder.create();
					alertDialog.show();
					
				} else {

					Toast.makeText(
							LoginActivity.this,
							LoginActivity.this
									.getString(R.string.wrong_user_password),
							Toast.LENGTH_LONG).show();
				}

			}
		});

//		forgetPasswordButton.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				intent = new Intent(LoginActivity.this,
//						ForgetPasswordActivity.class);
//				LoginActivity.this.startActivity(intent);
//
//			}
//		});
		
		forgetPassword.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				intent = new Intent(LoginActivity.this,
						ForgetPasswordActivity.class);
				LoginActivity.this.startActivity(intent);
			}
		});

//		signUpButton.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				intent = new Intent(LoginActivity.this, SignUpActivity.class);
//				LoginActivity.this.startActivity(intent);
//
//			}
//		});
		
		signUp.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				intent = new Intent(LoginActivity.this, SignUpActivity.class);
				LoginActivity.this.startActivity(intent);

			}
		});

	}

}
